
<template>
  <div class="recommendRoot">
    <div class="recommend" v-show="musicList.length">

      <el-carousel :interval="4000" type="card" height="180px">
        <el-carousel-item v-for="(v,i) in  bannerData" :key="i">
          <img :src="v.imageUrl" alt="">
        </el-carousel-item>
      </el-carousel>
      <div class="musicList">
        <h4>推荐列表<i class="iconfont icon-arrow-right-bold"></i></h4>
        <list-card :listCardData='musicList' @itemCardClick='handleClick' />
      </div>
    </div>
  </div>
</template>

<script>
import { reqPersonalized, reqBanner } from '@/network/api'
import { reactive, onMounted, toRefs } from 'vue'
import ListCard from '@/components/listCard/ListCard.vue'
import { useRouter } from 'vue-router'
export default {
  name: 'Recommend',
  components: { ListCard },
  setup() {
    const data = reactive({
      bannerData: [],
      musicList: []
    })
    const router = useRouter()
    const getBanner = async () => {
      const res = await reqBanner()
      if (res.code === 200) {
        data.bannerData = res.banners
      }
    }
    const getMusicList = async () => {
      const res = await reqPersonalized()
      if (res.code === 200) {
        data.musicList = res.result
      }
    }
    const handleClick = id => {
      router.push('/musiclistdetail/' + id)
    }
    onMounted(() => {
      getBanner()
      getMusicList()
    })
    return {
      ...toRefs(data),
      handleClick
    }
  }
}
</script>

<style scoped>
.recommendRoot {
  display: flex;
  justify-content: center;
}
.recommend {
  max-width: 1000px;
  width: 100%;
}
.el-carousel {
  margin: 0 auto;
  width: 800px;
}
.el-carousel__item {
  border-radius: 10px;
}
.el-carousel__item img {
  height: 100%;
}
.musicList {
  width: 100%;
  margin: 20px 10px;
}
.musicList h4 {
  margin-bottom: 10px;
  color: #333;
}
</style>